//
//  LoginViewController.m
//
//
//  Created by gynjobs on 2017/8/9.
//  Copyright © 2017年 gynjobs. All rights reserved.
//

#import "LoginViewController.h"
#import "LoginForgetPwdController.h"
#import "LoginUserRegistController.h"
@interface LoginViewController ()

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *marginLoginButton;
@property (weak, nonatomic) IBOutlet UIButton *backButton;
- (IBAction)backButtonAction:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UITextField *teleTextF;
@property (weak, nonatomic) IBOutlet UITextField *pwdTextF;
@property (weak, nonatomic) IBOutlet UIView *loginBackView;
@property (weak, nonatomic) IBOutlet UILabel *loginTitleLable;
@property (weak, nonatomic) IBOutlet UIView *quickLoginBackView;
@property (weak, nonatomic) IBOutlet UILabel *quickLoginTitleLable;
@property (strong, nonatomic) IBOutlet UITapGestureRecognizer *tapLogin;
- (IBAction)ClickLoginView:(UITapGestureRecognizer *)sender;
@property (strong, nonatomic) IBOutlet UITapGestureRecognizer *tapForgetPwd;
- (IBAction)ClickForgetView:(UITapGestureRecognizer *)sender;
@property (strong, nonatomic) IBOutlet UITapGestureRecognizer *tapQuickLogin;
- (IBAction)clickQuickLoginView:(UITapGestureRecognizer *)sender;
@property (strong, nonatomic) IBOutlet UITapGestureRecognizer *tapRegister;
- (IBAction)clickRegisterView:(UITapGestureRecognizer *)sender;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.marginLoginButton.constant = R_Y_H(95);
    [self setKeyBoardShowOrHidden];
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/**
 设置键盘推动View滚动
 */
- (void)setKeyBoardShowOrHidden {
    //设置键盘弹出功能启用
    IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
    //设置键盘弹出功能启用
    keyboardManager.enable = YES;
    //键盘弹出距离text的距离
    keyboardManager.keyboardDistanceFromTextField = 20.0;
    //点击空白处是否返回键盘
    keyboardManager.shouldResignOnTouchOutside = YES;
    //键盘上方是否有文本提示框
    keyboardManager.enableAutoToolbar = YES;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)backButtonAction:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
-(LoginMainAction *)loginMainAction{
    if (_loginMainAction==nil) {
        _loginMainAction = [[LoginMainAction alloc]init];
    }
    return _loginMainAction;
}
- (IBAction)ClickLoginView:(UITapGestureRecognizer *)sender {
   
    NSString * userName = self.teleTextF.text;
    
    NSString * passWord = self.pwdTextF.text;
    if (userName.length <= 0) {
        [self showToastAddWithTitle:@"手机号不能为空"];
        return;
    }else if (passWord.length <= 0) {
        [self showToastAddWithTitle:@"密码不能为空"];
        return;
    }
    [LoadingAnimalView showWhiteLoadingAddedTo:self.view];
    [self.loginMainAction loginWithUserName:userName withPassWord:passWord withCallBlock:^(id error_msg) {
        [LoadingAnimalView hideLoadingForView:self.view];
        if (error_msg) {
            [self showToastAddWithTitle:error_msg];
        }else {
            [[NSUserDefaults standardUserDefaults]setObject:[NSNumber numberWithBool:YES] forKey:ISLOGIN];
            [self backButtonAction:self.backButton];
//            if (goBack) {
//                [loginMainAction gorGoBackToMeViewController];
//            }
//            if (self.isRn) {
//                UIApplication *application = [UIApplication sharedApplication];
//                UIWindow *window = application.keyWindow;
//                
//                
//                
//                UIViewController * rootViewC= window.rootViewController;
//                [rootViewC.navigationController popViewControllerAnimated:YES];
//            }else{
//                [self dismissViewControllerAnimated:YES completion:nil];
//            }
        }
    }];
}
- (IBAction)ClickForgetView:(UITapGestureRecognizer *)sender {
    LoginForgetPwdController *forgetPwd = [[LoginForgetPwdController alloc]init];
    [self.navigationController pushViewController:forgetPwd animated:YES];
}
- (IBAction)clickQuickLoginView:(UITapGestureRecognizer *)sender {
}
- (IBAction)clickRegisterView:(UITapGestureRecognizer *)sender {
    LoginUserRegistController *regiestC = [[LoginUserRegistController alloc]init];
    [self.navigationController pushViewController:regiestC animated:YES];
}
@end
